import 'package:flutter/material.dart';
import 'package:wallet_utils/color.dart';

import 'custom_kb_btn.dart';
import 'key_event.dart';

/// 自定义密码 键盘

class MyKeyboard extends StatefulWidget {
  final callback;

  MyKeyboard(this.callback);

  @override
  State<StatefulWidget> createState() {
    return new MyKeyboardStat();
  }
}

class MyKeyboardStat extends State<MyKeyboard> {
  final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();

  /// 定义 确定 按钮 接口  暴露给调用方
  ///回调函数执行体
  var backMethod;
  void onCommitChange() {
    widget.callback(new KeyEvents("commit"));
  }

  void onOneChange(BuildContext cont) {
    widget.callback(new KeyEvents("1"));
  }

  void onTwoChange(BuildContext cont) {
    widget.callback(new KeyEvents("2"));
  }

  void onThreeChange(BuildContext cont) {
    widget.callback(new KeyEvents("3"));
  }

  void onFourChange(BuildContext cont) {
    widget.callback(new KeyEvents("4"));
  }

  void onFiveChange(BuildContext cont) {
    widget.callback(new KeyEvents("5"));
  }

  void onSixChange(BuildContext cont) {
    widget.callback(new KeyEvents("6"));
  }

  void onSevenChange(BuildContext cont) {
    widget.callback(new KeyEvents("7"));
  }

  void onEightChange(BuildContext cont) {
    widget.callback(new KeyEvents("8"));
  }

  void onNineChange(BuildContext cont) {
    widget.callback( KeyEvents("9"));
  }

  void onZeroChange(BuildContext cont) {
    widget.callback( KeyEvents("0"));
  }

  /// 点击删除
  void onDeleteChange() {
    widget.callback( KeyEvents("del"));
  }

  @override
  Widget build(BuildContext context) {
    return  Container(
      key: _scaffoldKey,
      width: double.infinity,
      height: 250.0,
      color: ColorManager.colorF2F2F2,
      padding: const EdgeInsets.only(top: 6, left: 6),
      child:  Column(
        children: <Widget>[
          ///  第一行
           Row(
            children: <Widget>[
              CustomKbBtn(
                  text: '1', callback: (val) => onOneChange(context)),
              CustomKbBtn(
                  text: '2', callback: (val) => onTwoChange(context)),
              CustomKbBtn(
                  text: '3', callback: (val) => onThreeChange(context)),
            ],
          ),

          ///  第二行
           Row(
            children: <Widget>[
              CustomKbBtn(
                  text: '4', callback: (val) => onFourChange(context)),
              CustomKbBtn(
                  text: '5', callback: (val) => onFiveChange(context)),
              CustomKbBtn(
                  text: '6', callback: (val) => onSixChange(context)),
            ],
          ),

          ///  第三行
           Row(
            children: <Widget>[
              CustomKbBtn(
                  text: '7', callback: (val) => onSevenChange(context)),
              CustomKbBtn(
                  text: '8', callback: (val) => onEightChange(context)),
              CustomKbBtn(
                  text: '9', callback: (val) => onNineChange(context)),
            ],
          ),

          ///  第四行
           Row(
            children: <Widget>[
              CustomKbBtn(text: '', callback: (val) => null),
              // CustomKbBtn(text: '', callback: (val) => onDeleteChange()),
              CustomKbBtn(
                  text: '0', callback: (val) => onZeroChange(context)),
              CustomKbBtn(text: '删除', callback: (val) => onDeleteChange()),
            ],
          ),
        ],
      ),
    );
  }
}
